home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_06_02 / v6n2065a.txt < prev    next >
Text File  |  1989-09-26  |  3KB  |  100 lines

  1. ----------
  2. WRITTEN:        25/10/87
  3. -------
  4. PURPOSE:        This is one of a series of files which take
  5. -------         advantage of INT 21H functions under MS-DOS.
  6.                 In each case the error situation is marked by
  7.                 the carry flag being set.   We use the De Smet
  8.                 external variable '_carryf' to see whether the
  9.                 carry is set on return from the function.
  10.                 If so, the error code can be used to obtain
  11.                 information about the specific error.
  12.  
  13. USAGE:          int FUN3CH(name, attr, &_carryf)
  14. -----           char *name;  (ASCIIZ string)
  15.                 int attr;
  16.                 char *_carryf;
  17.  
  18. DEPENDENCIES:           De Smet C V 2.44+
  19. ------------
  20. Copyright 1987 - Cogar Computer Services Pty. Ltd
  21. ---------------------------------------------------------------------
  22.  
  23. /*
  24.     First declare the name of the routine under the heading 'CSEG'.
  25.     Note the underscore needed at the end of the name.
  26. */
  27.  
  28. CSEG
  29. PUBLIC FUN3CH_
  30.  
  31. /*
  32.     The actual coding of the function follows.   Note the technique
  33.     to save the setting of the base pointer.   For the purposes of
  34.     these programmes it is not necessary to make ES common with DS,
  35.     but this is generally useful in ASM88 programmes.
  36. */
  37.  
  38. FUN3CH_:
  39.     push    bp    ; normal De Smet C start
  40.     mov    bp,sp    ; point to the stack
  41.     mov    ax,ds    ; and make ES common with DS
  42.     mov    es,ax
  43. ----------------------------------------------------------------------
  44.        The unique programme follows.
  45. ----------------------------------------------------------------------
  46. /*
  47.     Take the values we need off the stack.   Note the first value is
  48.     located at 'bp+4' because the return address is pushed first and
  49.     then 'bp' was pushed by us as we started the programme.
  50.     The values are placed into the three registers as required by
  51.     MS-DOS so that INT 21H can be used.
  52. */
  53.  
  54.     mov    dx,[bp+4]    ; put address of file name into DX
  55.     mov    cx,[bp+6]    ; put the file attribute into CX
  56.     mov    ah,3ch    ; put the Function No. into AH
  57.     int    21h
  58.  
  59. /*
  60.     Now test to see whether the carry flag is set, which will tell
  61.     us that an error has occurred.   If there is an error we use
  62.     a conditional jump to the code to handle this situation.
  63. */
  64.  
  65.     jc    FUN3CH_ERROR
  66.  
  67. /*
  68.     If there is no error then we just jump over the error coding
  69.     to the normal return routine.
  70. */
  71.  
  72.     jmp    FUN3CH_QUIT
  73.  
  74. /*
  75.     If there has been an error then we get the address of the
  76.     (external) carry flag variable and send the value of one
  77.     to this address.   This is an example of the coding which
  78.     can be used to send a value to any external variable which
  79.     has previously had its address passed to the function.
  80. */
  81.  
  82. FUN3CH_ERROR:
  83.     mov    si,[bp+8]    ; put address of '_carryf' variable into SI
  84.     mov    byte [si],1    ; and then return with _carryf = 1
  85.  
  86. /*
  87.     From this point the error routine just 'falls through' to the
  88.     normal programme termination where both the starting stack
  89.     conditions are restored and the starting Base Pointer is
  90.     restored.
  91. */
  92.  
  93. ----------------------------------------------------------------------
  94.        Normal programme termination.
  95. ----------------------------------------------------------------------
  96. FUN3CH_QUIT:
  97.     pop    bp    ; restore starting conditions
  98.     ret
  99. ----------------------------------------------------------------------
  100.